Many computer graphic images are created by mathematically modeling the interaction of light with a three dimensional scene from a given viewpoint. This process, called “rendering,” generates a two-dimensional image of the scene from the given viewpoint, and is analogous to taking a photograph of a real-world scene. Rendering is typically a series of pipelined operations whereby two- or three-dimensional points in space are computed and projected into a two-dimensional space corresponding to the given viewpoint. Those points are assembled to form geometric primitives, which are rendered pixel-by-pixel.
As the demand for computer graphics, and in particular for real-time computer graphics, has increased, computer systems with graphics processing subsystems adapted to accelerate the rendering process have become widespread. In these computer systems, the rendering process is divided between a computer's general purpose central processing unit (CPU) and the graphics processing subsystem, architecturally centered about a graphics processing unit (GPU). Typically, the CPU performs high-level operations, such as determining the position, motion, and collision of objects in a given scene. From these high level operations, the CPU generates a set of rendering commands and data defining the desired rendered image or images. For example, rendering commands and data can define scene geometry, lighting, shading, texturing, motion, and/or camera parameters for a scene. The graphics processing subsystem creates one or more rendered images from the set of rendering commands and data.
Scene geometry is typically represented by geometric primitives, such as points, lines, polygons (for example, triangles and quadrilaterals), and curved surfaces, defined by one or more two- or three-dimensional vertices. Those primitives are rendered pixel-by-pixel. Each vertex may have additional scalar or vector attributes used to determine qualities such as the color, transparency, lighting, shading, and animation of the vertex and its associated geometric primitives. Each pixel is subject to calculations to arrive at appropriate attribute values. The most common example is lighting computations for each pixel.
Many graphics processing subsystems are highly programmable through an application programming interface (API), enabling complicated lighting and shading algorithms, among other things, to be implemented. To exploit this programmability, applications can include one or more graphics processing subsystem programs, which are executed by the graphics processing subsystem in parallel with a main program executed by the CPU. Although not confined merely to implementing shading and lighting algorithms, these graphics processing subsystem programs are often referred to as “shading programs” or “programmable shaders.”